home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 February / macformat-047.iso / Shareware Plus / Developers / LogoMation 1.1.4 ƒ / Examples / mouse ops / mouse ops
Encoding:
Text File  |  1996-10-24  |  2.4 KB  |  82 lines  |  [UVtx/UVtl]

  1. //////////////////////////////////////////////////////////
  2. // This program demonstrates reading the mouse location //
  3. // and displaying its coords in a continueous way.  If  //
  4. // the mouse button is clicked, the line and coords     //
  5. // turn red.                                            //
  6. // As usual, abort by cmd-.                             //
  7. //////////////////////////////////////////////////////////
  8.  
  9. white = "65535,65535,65535"
  10. black = "0,0,0"
  11. red   = "65535,0,0"
  12. Width 2
  13. // repeat forever -- read the mouse location and draw it
  14. Repeat 10000000
  15.     drawXY(mouseX(), mouseY())
  16.  
  17. // // // // // // 
  18.  
  19. ///////////////////////////////////////////////////////
  20. // function drawXY: display the mouse (x,y) coords,  //
  21. // and draw a line from (0,0) to (x,y).              //
  22. ///////////////////////////////////////////////////////
  23. Function drawXY(x, y)
  24.     If (! defined(lastX))       // very first time
  25.         lastX = 0
  26.         lastY = 0
  27.  
  28.     // return if no change -- this will avoid flicker
  29.     If (x = lastX & y = lastY) 
  30.         Return
  31.     // get here if a new mouse location
  32.  
  33.     // display the coords, erase old line and draw new
  34.     printLoc(x, y)
  35.     if ( click(0) )
  36.         color = red
  37.     else
  38.         color = black
  39.     lineFrom00(lastX, lastY, white)
  40.     lineFrom00(x, y, color)
  41.  
  42.     // update the "old" mouse location to current
  43.     lastX = x
  44.     lastY = y
  45.     
  46.     
  47. ///////////////////////////////////////////////////////
  48. // function printLoc - draw a yellowish rectangle as //
  49. // background, print the coords in it                //
  50. ///////////////////////////////////////////////////////
  51. Function printLoc(x, y)
  52.     // rectangle as background
  53.     Up
  54.     Goto -width()/2, height()/2,0
  55.     Down
  56.     Fill 1,64398,65535,35928  // yellowish
  57.         Repeat 2
  58.             Forward 120
  59.             Right 90
  60.             Forward 17
  61.             Right 90
  62.     // now print the coords.
  63.     Up
  64.     Right 45
  65.     Forward 18
  66.     Print "x=" . x . "  y=". y
  67.     
  68.     
  69. ///////////////////////////////////////////////////////////
  70. // function lineFrom00 - draw a line from (0,0) to (x,y) //
  71. // with a given R,G,B color                              //
  72. ///////////////////////////////////////////////////////////
  73. Function lineFrom00(x, y, color)
  74.     // erase old line, draw a line from (0,0) to
  75.     // the mouse location, then draw a diamond at (0,0)
  76.     Color color
  77.     Up
  78.     Goto x, y, 0
  79.     Down
  80.     Goto 0,0,0
  81.  
  82.